export default () => {
    const token = useState<string | null>('token', () => null);

    const initToken = () => {
        if (process.client) {
            const cache = localStorage.getItem('token');
            if (cache) token.value = cache;
        }
    };

    const setToken = (value: string) => {
        token.value = value;
        if (process.client) localStorage.setItem('token', value);
    };

    const clearToken = () => {
        token.value = null;
        if (process.client) localStorage.removeItem('token');
    };

    return { token, initToken, setToken, clearToken };
};